﻿$(function () {

    //light Box
    $("a[href='membership.aspx']").colorbox({ width: "85%", height: "65%", iframe: true });
    $("a[href='forgottenPassword.aspx']").colorbox({ width: "50%", height: "50%", iframe: true });
    $("a[href='resendActivationMail.aspx']").colorbox({ width: "50%", height: "50%", iframe: true });
    $("a[href='users/changePass.aspx']").colorbox({ width: "50%", height: "50%", iframe: true });
    $("a[href='users/changeAccount.aspx']").colorbox({ width: "65%", height: "60%", iframe: true });
    $("a[href='users/unsubscribe.aspx']").colorbox({ width: "50%", height: "35%", iframe: true });

    $('#havalbox,#taliyabox').hide();
    $('#step0,#step3').corner("7px");
    $('#step2,#step1').corner("7px");
    $('#irancell,#taliya,#haval').corner("10px tr tl");


    $("#selected").addClass("select");


    $(".VoucherPrice").text("");
    $(".VoucherAmount").text("");
    $("#[id$=_TotalPrice]").val("");

    $('#taliya').click(function () {
        hidebox();
        clearform();
        $('#taliyabox').fadeIn("slow");
        $('.companylogo').slideDown("slow");
    });
    $('#irancell').click(function () {
        hidebox();
        clearform();
        $('#irancellbox').fadeIn("slow");
        $('.companylogo').slideDown("slow");
    });
    $('#haval').click(function () {
        hidebox();
        clearform();
        $('#havalbox').fadeIn("slow");
        $('.companylogo').slideDown("slow");
    });

    $(".input").addClass("idle");
    $(".input").focus(function () {
        $(this).addClass("activeField").removeClass("idle");
    }).blur(function () {
        $(this).removeClass("activeField").addClass("idle");
    });

    /*
    $(".btn").mouseover(function () {

    $(this).css("background-image", "url(app_Themes/default/images/submitover.png)");
    });
    

    $(".btn").mouseout(function () {

    $(this).css("background-image", "url(app_Themes/default/images/submit.png)");
    });
    */


    $("#banklist td").each(function () {

        var id = $(this).find('a').attr('id');
        $.ajax(
       {
           type: "POST",
           url: "jquery.aspx/GetActivePaymentGateway",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           data: "{'id':'" + id + "'}",
           success: function (msg) {
               if (msg.d) {
                   $(".b" + id).parent().mouseover(function () {
                       $(".b" + id).parent().addClass("border");
                   });

                   $(".b" + id).parent().mouseout(function () {
                       $(".b" + id).parent().removeClass("border");
                   });

                   $(".b" + id).parent().click(function () {
                       $("#banklist td").removeClass("select");
                       $(".b" + id).parent().addClass("select");
                       $("#[id$=_DDSelectBank]").val(id);
                   });
               }
               else {
                   $(".b" + id).parent().mouseover(function () {
                       $(".b" + id).parent().addClass("notvalid");
                   });

                   $(".b" + id).parent().mouseout(function () {
                       $(".b" + id).parent().removeClass("notvalid");
                   });
               }

           },
           failure: function (msg) {
               alert(msg.d);
           }
       });

    });

    var price = 0;
    $("#[id$=_rbIranCell]").click(function () {

        $.ajax(
       {
           type: "POST",
           url: "jquery.aspx/GetPriceByVoucherTypeId",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           data: "{'id':'" + $("#[id$=_rbIranCell] input:radio:checked").val() + "'}",
           success: function (msg) {
               $(".VoucherPrice").text(Comma(msg.d) + " ریال ");
               $("#[id$=_TotalPrice]").val(Comma($("[id$='_VoucherCount']").val() * msg.d) + " ریال ");
               price = msg.d;
           },
           failure: function (msg) {
               alert(msg.d);
           }
       });
    });


    $("#[id$=_rbTaliya]").click(function () {

        $.ajax(
       {
           type: "POST",
           url: "jquery.aspx/GetPriceByVoucherTypeId",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           data: "{'id':'" + $("#[id$=_rbTaliya] input:radio:checked").val() + "'}",
           success: function (msg) {
               $(".VoucherPrice").text(Comma(msg.d) + " ریال ");
               $("#[id$=_TotalPrice]").val(Comma($("[id$='_VoucherCount']").val() * msg.d) + " ریال ");
               price = msg.d;
           },
           failure: function (msg) {
               alert(msg.d);
           }
       });
    });

    $("#[id$=_rbHamrah]").click(function () {

        $.ajax(
       {
           type: "POST",
           url: "jquery.aspx/GetPriceByVoucherTypeId",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           data: "{'id':'" + $("#[id$=_rbHamrah] input:radio:checked").val() + "'}",
           success: function (msg) {
               $(".VoucherPrice").text(Comma(msg.d) + " ریال ");
               $("#[id$=_TotalPrice]").val(Comma($("[id$='_VoucherCount']").val() * msg.d) + " ریال ");
               price = msg.d;
           },
           failure: function (msg) {
               alert(msg.d);
           }
       });
    });

    $("[id$='_VoucherCount']").change(function () {
        if ($(".VoucherPrice").text() != "") {
            $("#[id$=_TotalPrice]").val(Comma($("[id$='_VoucherCount']").val() * price) + " ریال ");
        }
    });
});

function hidebox()
{ $('#havalbox,#taliyabox,#irancellbox,.companylogo').hide(); }

function Comma(SS) {
    var T = "", S = String(SS), L = S.length - 1, C, j;
    for (j = 0; j <= L; j++) {
        T += C = S.charAt(j);
        if (j < L && (L - j) % 3 == 0 && C != "-") {
            T += ",";
        }
    }
    return T;
}


function clearform() {
    $("#[id$=_rbTaliya] input:radio ").attr('checked', false);
    $("#[id$=_rbHamrah] input:radio").attr('checked', false);
    $("#[id$=_rbIranCell] input:radio").attr('checked', false);
    $(".VoucherPrice").text('');
    $("#[id$=_TotalPrice]").val('');
    $("[id$='_VoucherCount']").val('1');
}

function CheckActive(id) {
    var value = '';



}

   

